
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author William
 */
public class xmltry2 {
    public static void main(String args[]){
        try {
            DocumentBuilderFactory DOMBldrFactory = DocumentBuilderFactory.newInstance();
            DOMBldrFactory.setNamespaceAware(true);
            DOMBldrFactory.setValidating(true);
            DOMBldrFactory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", XMLConstants.W3C_XML_SCHEMA_NS_URI);
            DOMBldrFactory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource", new File("resources/DBx.conf.xsd"));

            DocumentBuilder DOMBldr = DOMBldrFactory.newDocumentBuilder();
            File xmlsrc = new File("resources/DBx.conf.xml");
            System.out.println("Source XML exists? " + xmlsrc.exists());
            Document DOM = DOMBldr.parse(new File("resources/DBx.conf.xml"));
            Element query1 = DOM.getElementById("QUERY_1");
            System.out.println("Query exists? " + (query1 != null));
            System.out.println("Query Description: " + query1.getAttribute("description"));
        }
        catch (SAXException ex) {
            Logger.getLogger(xmltry2.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(xmltry2.class.getName()).log(Level.SEVERE, null, ex);
        }        catch (ParserConfigurationException ex) {
            Logger.getLogger(xmltry2.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
